package com.hexu.event.service;

import com.hexu.event.dao.ArticleSpecieDao;
import com.hexu.event.entity.Specie;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

import static com.hexu.event.util.WebUtil.show;

public class SpecieService {
    ArticleSpecieDao articleSpecieDao = new ArticleSpecieDao();

    //增加文章种类
    public boolean addSpecie(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用请求对象读取请求头参数信息，得到分类
        String name = request.getParameter("specie");
        Specie specie = new Specie(null,name);
        if(name.equals("")){
            return false;
        }

        boolean flag = articleSpecieDao.addSpecie(specie);

        show(flag, request, response,"添加成功","添加失败","/hexu/addSpecie.html","/hexu/addSpecie.html");

        return flag;
    }


    //删除文章种类
    public boolean deleteSpecie(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //调用请求对象读取请求头参数信息，得到分类
        String name = request.getParameter("specie");
        boolean flag = articleSpecieDao.deleteSpecie(name);
        show(flag, request, response,"删除成功","删除失败","/hexu/administrator/deleteSpecie","/hexu/administrator/deleteSpecie");

        return flag;
    }
}
